#!/usr/bin/env ruby

LKP_SRC = ENV['LKP_SRC'] || File.dirname(File.dirname(File.realpath($PROGRAM_NAME)))

require "#{LKP_SRC}/lib/statistics"

$stdin.each_line do |line|
  case line
  when /Elapsed Time/
    puts "LAT.elapsed_time: #{line.split[2]}"
    puts "JIT.elapsed_time.stddev: #{line.split[3].gsub(/[()]/, '')}" if line.split[3]
  when /User Time/
    puts "LAT.user_time: #{line.split[2]}"
    puts "JIT.user_time.stddev: #{line.split[3].gsub(/[()]/, '')}" if line.split[3]
  when /System Time/
    puts "LAT.system_time: #{line.split[2]}"
    puts "JIT.system_time.stddev: #{line.split[3].gsub(/[()]/, '')}" if line.split[3]
  when /Percent CPU/
    puts "LAT.percent_cpu: #{line.split[2]}"
    puts "JIT.percent_cpu.stddev: #{line.split[3].gsub(/[()]/, '')}" if line.split[3]
  when /Context Switches/
    puts "LAT.context_switches: #{line.split[2]}"
    puts "JIT.context_switches.stddev: #{line.split[3].gsub(/[()]/, '')}" if line.split[3]
  when /Sleeps/
    puts "LAT.sleeps: #{line.split[1]}"
    puts "JIT.sleeps.stddev: #{line.split[2].gsub(/[()]/, '')}" if line.split[2]
  end
end
